using System;
using System.Collections.Generic;
using System.Text;
using QLKS.HeThongBUS;
using System.Data;
using System.Data.OleDb;
using QLKS.HeThongDAO;

namespace QLKS.HeThongDAO
{
    public class NV_DAO
    {
        // goi bang nhan vien
        public static DataTable SelectAllNV()
        {
            string sql = "SELECT MaNhanVien as [Mã],TenNhanVien as [Tên NV],NgaySinh as [Ngày Sinh],CMND,TenChucVu as [Chức Vụ],MaChucVu,DiaChi as [Địa chỉ],TaiKhoan as [Tài khoản],MatKhau as [Mật Khẩu],LoaiTaiKhoan as [Loại quyền] FROM Chucvu,NhanVien where Chucvu.MaChucVu = NhanVien.ChucVu";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        
        //Them 1 nhan vien 
        public static bool InsertNV(NV_DTO nv)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "INSERT INTO NhanVien(TenNhanVien,NgaySinh, CMND, ChucVu, DiaChi,TaiKhoan,MatKhau,LoaiTaiKhoan) VALUES ('" +
                nv.TenNhanVien + "','" +
                nv.Ngaysinh + "','" +
                nv.Cmnd + "','" +
                nv.Machucvu + "','" +
                nv.Diachi+ "','" +
                nv.Taikhoan + "','" +
                nv.Matkhau + "','" +
                nv.Loaitaikhoan + "')";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        // cap nhat khach hang
        public static bool UpdateNV(NV_DTO nv)
        {
            try
            {
                string sql = "UPDATE NhanVien SET TenNhanVien = '" + nv.TenNhanVien + "',NgaySinh = '" + nv.Ngaysinh + "',CMND = '" + nv.Cmnd + "',ChucVu = '" + nv.Machucvu + "',DiaChi = '" + nv.Diachi + "',TaiKhoan = '" + nv.Taikhoan + "',MatKhau = '" + nv.Matkhau + "',LoaiTaiKhoan = '" + nv.Loaitaikhoan + "' where MaNhanVien=" + nv.Manv;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        // xoa 1 khach hang

        public static bool DeleteNV(NV_DTO nv)
        {
            try
            {
                string sql = "DELETE FROM NhanVien WHERE MaNhanVien=" + nv.Manv;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //cbb chuc vu
        public static DataTable DSCV()
        {
            string sql = "SELECT * FROM ChucVu";
            return Config.AccessHelper.ExecuteQuery(sql);
        }





    }
}
